package com.yicheng.push;

import com.yicheng.util.EnglishWorlds;
import com.yicheng.util.Riqi;
import com.yicheng.util.Tianqi;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;

public class Pusher {
    private static String appId = "wx231f9709f36aa532";
    private static String secret = "22263a27804d09e7f95b59cb8cc7ce7c";



    public static void push(){
        //1，配置
        WxMpInMemoryConfigStorage wxStorage = new WxMpInMemoryConfigStorage();
        wxStorage.setAppId(appId);
        wxStorage.setSecret(secret);
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxStorage);
        //2,推送消息
        WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
                .toUser("otGW45g9BtcbSXZNMrwGYmdtlO8U")//用户id
                .templateId("Rdc0kHLW8pX2lw9pL9m2r1da_-pnRL6tiuA3rY3xWX4")//模板消息id
                .build();
        //3,如果是正式版发送模版消息，这里需要配置你的信息
//        templateMessage.addData(new WxMpTemplateData("test", "这是测试的账号滴滴滴滴","#00FFFF"));

//        日期
        templateMessage.addData(new WxMpTemplateData("riqi", Riqi.riqi(), "#0095f9"));//日期

//      获取天气
        String[] strings1 = Tianqi.tianqi();
        templateMessage.addData(new WxMpTemplateData("tianqi",strings1[0],"#f60000"));
        templateMessage.addData(new WxMpTemplateData("wendu", strings1[1], "#f5dd07"));
        templateMessage.addData(new WxMpTemplateData("richu", strings1[2],"#07f5aa"));
        templateMessage.addData(new WxMpTemplateData("feng", strings1[3], "#f107f5"));
        templateMessage.addData(new WxMpTemplateData("tip", strings1[4],"#06b8f9"));


//        每日金句 类的名字没改，无所谓
        EnglishWorlds englishWorlds = new EnglishWorlds();
        String[] strings2 = englishWorlds.englishWorlds();
        templateMessage.addData(new WxMpTemplateData("content", strings2[0], "#C71585"));//文案
        templateMessage.addData(new WxMpTemplateData("source", strings2[1], "#e450ae"));//作者
        try {
            System.out.println(templateMessage.toJson());
            System.out.println(wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage));
        } catch (Exception e) {
            System.out.println("推送失败：" + e.getMessage());
            e.printStackTrace();
        }
    }
}
